import 'package:flutter/material.dart';
import 'package:flutter_application_1/components/load_more/load_more.dart';
import 'package:flutter_application_1/components/lottie_refresh_header/lottie_refresh_header.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

import './components/game_item.dart';

/// 街机
class TabBar3 extends StatefulWidget {
  final Color primaryColor;
  final Color bgColor;

  TabBar3({
    this.primaryColor = Colors.transparent,
    this.bgColor = Colors.transparent,
  });

  @override
  _TabBar3State createState() => _TabBar3State();
}

class _TabBar3State extends State<TabBar3> with AutomaticKeepAliveClientMixin {
  RefreshController _controller = RefreshController();

  // 下拉刷新
  Future _onRefresh() async {
    await Future.delayed(Duration(milliseconds: 1500));
    _controller.refreshCompleted();
  }

  @override
  bool get wantKeepAlive => true;

  @override
  Widget build(BuildContext context) {
    return RefreshConfiguration(
      headerTriggerDistance: LottieRefreshHeader.size,
      child: SmartRefresher(
        controller: _controller,
        // 下拉刷新
        enablePullDown: true,
        onRefresh: _onRefresh,
        header: LottieRefreshHeader(),
        // 上拉加载
        enablePullUp: true,
        footer: CustomFooter(
          loadStyle: LoadStyle.HideAlways,
          builder: (_, __) => LoadMore(
            status: LoadMoreStatus.NoMore,
          ),
        ),
        child: CustomScrollView(
          slivers: [
            SliverToBoxAdapter(
              child: SizedBox(height: 5),
            ),
            SliverToBoxAdapter(
              child: Container(
                margin: EdgeInsets.only(
                  bottom: 10,
                  left: 10,
                  right: 10,
                ),
                padding: EdgeInsets.all(20),
                decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.circular(8),
                ),
                child: Wrap(
                  runSpacing: 10,
                  children: List.generate(
                    20,
                    (index) => GameItem(
                      data: GameItemData(
                        cover:
                            'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fwww.soumeitu.com%2Fwp-content%2Fuploads%2F2020%2F07%2F5f16b2f4a1dc0.jpg&refer=http%3A%2F%2Fwww.soumeitu.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1628403692&t=c6793faf29dad4315f5241a3fbd7d805',
                        avatar:
                            'https://i2.hdslb.com/bfs/face/27956154ebc30ab1de758b6ad53daee844a2e42c.jpg@160w_160h_1c.jpg',
                        name: '疯狂魔鬼城$index号',
                        price: (20 + index).toStringAsFixed(0),
                        peopleCount: index,
                      ),
                    ),
                  ),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
